﻿@{
    Layout = null;
}
<script type="text/javascript">
    //----------------------用户-----------------------------
    var zNodes_Permission_Role_SelectRole = [];
    var zTree_Permission_Role_SelectRole;
    var setting_Permission_Role_SelectRole;
    setting_Permission_Role_SelectRole = {
        checkable: true,
        isSimpleData: true,
        checkedCol: "Checked",
        async: true,
        asyncUrl: "/Permission/Role/GetRoleByzTree/0",
        nameCol: "Realname", //RealName
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        asyncDataFilter: zTreeOnAsyncSuccess_Permission_Role_SelectRole_ajaxDataFilter,
        callback: {
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Role_SelectRole,
            click: zTreeOnClick_Permission_Role_SelectRole
        }
    };

    //绑定数据之前对数据进行预处理
    function zTreeOnAsyncSuccess_Permission_Role_SelectRole_ajaxDataFilter(treeId, parentNode, childNodes) {
        if (childNodes) {
            var templist = $("#Permission_role_linkRoles_hidden_RolelistID").val().split(',');
            for (var i = 0; i < childNodes.length; i++) {
                for (var j = 0; j < templist.length; j++) {
                    if (childNodes[i].Id == templist[j]) {
                        childNodes[i].Checked = true;
                    }
                }
            }
        }
        return childNodes;
    }

    function zTreeOnAsyncSuccess_Permission_Role_SelectRole(event, treeId, treeNode, msg) {
        //异步成功
    }

    function zTreeOnClick_Permission_Role_SelectRole(event, treeId, treeNode) {
        //点击事件
    }
    //-----------------------------------------------------------------

    function Permission_Role_SelectRole_load() {

        zTree_Permission_Role_SelectRole = $("#Permission_Role_SelectRole_ul_RoleList").zTree(setting_Permission_Role_SelectRole, zNodes_Permission_Role_SelectRole);
    }

    //提交的方法
    function Permission_Role_SelectRole_bindsubmit() {
        $("#Permission_Role_SelectRole_btn_submit").bind("click", function () {
            //获取用户ID
            var submit_userNodes = zTree_Permission_Role_SelectRole.getCheckedNodes(true);
            var submit_roleIDs = "";
            var submit_roleNames = "";
            for (var i = 0; i < submit_userNodes.length; i++) {
                submit_roleIDs += submit_userNodes[i].Id + ",";
                submit_roleNames += submit_userNodes[i].Realname + ",";
            }
            if (submit_roleIDs.length > 0) {
                submit_roleIDs = submit_roleIDs.substring(0, submit_roleIDs.length - 1);
                submit_roleNames = submit_roleNames.substring(0, submit_roleNames.length - 1);
            }
            //判断是在职员添加的时候改模块
            var roleIDsCreateStaff = $("#roleIDs_Permission_Organize_CreateStaff");
            if (roleIDsCreateStaff.length > 0) {
                $("#roleIDs_Permission_Organize_CreateStaff").val(submit_roleIDs);
                $("#roleNames_Permission_Organize_CreateStaff").val(submit_roleNames);
            }
            //判断是在用户添加的时候改模块
            var roleIDsCreateUser = $("#roleIDs_Permission_User_CreateUser");
            if (roleIDsCreateUser.length > 0) {
                $("#roleIDs_Permission_User_CreateUser").val(submit_roleIDs);
                $("#roleNames_Permission_User_CreateUser").val(submit_roleNames);
            }
            $.pdialog.closeCurrent();
        });
    }

    $(document).ready(function () {
        Permission_Role_SelectRole_load();
        Permission_Role_SelectRole_bindsubmit();
    });
</script>
<div class="pageContentD">

    <div class="pageContent" layouth="40">
        <input type="hidden" id="Permission_Role_SelectRole_hidden_userID" value="@ViewBag.userID" />
    <input type="hidden" id="Permission_role_linkRoles_hidden_RolelistID" value="@ViewData["roleListID"]" />
    @if (ViewBag.userName != null && ViewBag.userName != "")
    {
        <ul class="searchBar">
            <li>
                <span>用户：</span>
                <i>@ViewBag.userName</i>
            </li>
        </ul>
    }
        <ul id="Permission_Role_SelectRole_ul_RoleList" class="ztree">
        </ul>
    </div>
    <div class='formBar'>
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="Permission_Role_SelectRole_btn_submit">
                    确定</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
